package com.xf.micro.core.filter;

import com.xf.micro.core.filter.chain.CoreFilterChain;
import com.xf.micro.core.filter.context.FilterContext;

import java.util.List;

/**
 * @author zouxf
 * @date 2023/12/26 16:24
 * @description
 */
public class GlobalFilterChain implements FilterChain {

    private CoreFilterChain preFilterChain = new CoreFilterChain();

    private CoreFilterChain postFilterChain = new CoreFilterChain();

    FilterContext filterContext = new FilterContext();

    @Override
    public void doPreFilterChain() throws Throwable {
        preFilterChain.doFilter(filterContext);
    }

    @Override
    public void doPostFilterChain() throws Throwable {
        postFilterChain.doFilter(filterContext);
    }

    public void addPreFilters(List<CoreFilter> coreFilters){
        for (CoreFilter coreFilter : coreFilters) {
            preFilterChain.addLast((LinkedCoreFilter) coreFilter);
        }
    }
}
